package cc.lishixi.book.service;

import cc.lishixi.book.dao.mapper.LendInfoRowMapper;
import cc.lishixi.book.entity.LendInfo;
import cc.lishixi.book.service.api.AbstractService;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by LiShixi on 2016/7/24 0024.
 * http://www.lishixi.cc
 */
@Component
public class LendInfoService extends AbstractService<LendInfo> {
    @Override
    public List<LendInfo> list() {
        return jdbcTemplate.query("select * from lendinfo", new LendInfoRowMapper());
    }

    @Override
    public boolean delete(Integer id) {
        return jdbcTemplate.update("delete from lendinfo where id=?", id) > 0;
    }

    @Override
    public boolean edit(LendInfo l) {
        String sql = "UPDATE `book`.`lendinfo` SET `readerId`=?, `bookcode`=?, `borrowdate`=?, `duedate`=?, `returndate`=?, `renew`=?, `overduedays`=?, `fine`=? WHERE  `id`=1;";
        return jdbcTemplate.update(sql, l.getReaderId(), l.getBookcode(), l.getBorrowdate(), l.getDuedate(), l.getReturndate(), l.getRenew(), l.getOverduedays(), l.getFine(), l.getId()) > 0;
    }

    @Override
    public boolean add(LendInfo l) {
        String sql = "INSERT INTO `book`.`lendinfo` (`readerId`, `bookcode`, `borrowdate`, `duedate`, `returndate`, `renew`, `overduedays`, `fine`) VALUES (?, ?, ?, ?, ?, ?, ?, ?);";
        return jdbcTemplate.update(sql, l.getReaderId(), l.getBookcode(), l.getBorrowdate(), l.getDuedate(), l.getReturndate(), l.getRenew(), l.getOverduedays(), l.getFine()) > 0;
    }
}
